package com.group.elmboot.util;

import com.aliyun.teaopenapi.models.Config;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;

public class SmsService {
    public static Client createClient() throws Exception {
        Config config = new Config()
                // 配置 AccessKey ID
                .setAccessKeyId("LTAI5tE8zNjU6dGuV22ofFCu")
                // 配置 AccessKey Secret
                .setAccessKeySecret("MoTHYSUAqqBpGYSYEqp3rJxPjOwcuV");
        
        // 配置 Endpoint
        config.endpoint = "dysmsapi.aliyuncs.com";

        Client aliClient=new Client(config);
        return aliClient;
    }

    public static int sendMessage(String userId,int Validation) throws Exception {
        // 初始化请求客户端
        Client client = SmsService.createClient();

        // 构造请求对象，请填入请求参数值
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(userId)
                .setSignName("24软工综合实践饿了吧")
                .setTemplateCode("SMS_472305268")
                .setTemplateParam("{code:"+Validation+"}");

        client.sendSms(sendSmsRequest);

        return 1;
    }
}